<template>
	<div class="updatePcPwd">
		<i class="el-icon-edit">修改密码</i>
		<el-form ref="form" label-width="80px" style="margin-top: 2%;">
			<el-form-item label="旧密码">
				<el-input v-model="low"></el-input>
			</el-form-item>
			<el-form-item label="新密码">
				<el-input v-model="pwd"></el-input>
			</el-form-item>
			<el-form-item label="密码确认">
				<el-input v-model="pwd2"></el-input>
			</el-form-item>
		</el-form>
		<el-button @click="doupdatePwd()">确认</el-button>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				low: '',
				pwd: '',
				pwd2: '',
				user: {}
			}
		},
		methods: {
			doupdatePwd() {
				this.user = {
					oldPwd: this.low,
					newPwd: this.pwd2
				}
				console.log(this.low);
				console.log(this.pwd);
				if (this.pwd != this.pwd2) {
					this.$message.error('两次密码不一致');

				} else {
					this.$postkv('/api/user/updatePwd', this.user).then((resp) => {
						console.log(resp.data.data);
						console.log(resp.data.msg);
						if (resp.data.msg == "旧密码输入有误") {
							this.$message.error('重新输入旧密码');
						} else {
							this.$message({
								showClose: true,
								message: '修改成功,请重新登录'
							});
							window.localStorage.clear();
							this.$router.push('/home');
						}


					})
				}
			}
		}
	}
</script>

<style>
	.updatePcPwd {
		width: 60%;
		margin-left: 5%;

	}

	.updatePcPwd i {
		margin-left: -45%;
	}

	.updatePcPwd form {
		width: 50%;
	}

	.updatePcPwd button {
		margin-left: -45%;
		border: none;
	}
</style>